package com.bdqn.Demo.service;


import com.bdqn.Demo.dao.SysUserMapper;
import com.bdqn.Demo.pojo.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import java.util.List;

@Scope("prototype")
@Service
public class SysUserServiceImpl implements SysUserService{
    @Autowired//@Resource
    private SysUserMapper sysUserMapper;

    /**
     * 查询用户列表
     */
    @Override
    public List<SysUser> selectSysUserList(SysUser sysUser) {
        try{
            return sysUserMapper.selectSysUserList(sysUser);
        }catch (RuntimeException e){
            e.printStackTrace();
            throw e;
        }
    }

    /**
     * 保存用户
     */
    public boolean add(SysUser sysUser){
        boolean result = false;
        try{
            if(sysUserMapper.add(sysUser) == 1){
                result = true;
                //测试事务回滚时，打开注释
                //throw new RuntimeException();
            }
        }catch (RuntimeException e){
            e.printStackTrace();
            throw e;
        }
        return result;
    }

    public SysUserMapper getSysUserMapper() {
        return sysUserMapper;
    }

    public void setSysUserMapper(SysUserMapper sysUserMapper) {
        this.sysUserMapper = sysUserMapper;
    }
}
